 global root "/Volumes/Workgroup/Lab/Lab-heimb/Montenovo/Volunteering Paper/Data"
global results "$root/07_results/RR/main"
global dictionaries "$root/Dictionaries"

cd "$root"

use appended_analytic_010305111719, clear 
//use fd_appended_analytic_010305111719, clear 

drop if education_head==.

xtile quantile_income=post_tax_income, nq(3)

gen whether_itemized_dummy= whether_itemized
replace whether_itemized_dummy=. if whether_itemized>5
replace whether_itemized_dummy=0 if whether_itemized==5
bysort quantile_income: sum whether_itemized_dummy
bysort quantile_income: sum whether_volunteer_person
bysort quantile_income: sum hours_volunteer_person
 
 generate whether_donation=.
replace whether_donation=0 if total_giving==0
replace whether_donation=1 if total_giving>0

bysort quantile_income: sum whether_donation
bysort quantile_income: sum total_giving

//Trend over time of volunteering rate and avg volunteering hs by quantile
preserve
collapse (mean) whether_volunteer_person, by(year quantile_income)
twoway line whether_volunteer_person year if quantile_income==1 || line whether_volunteer_person year if quantile_income==2 || line whether_volunteer_person year if quantile_income==3, legend(label(1 "First Income Quantile") label(2 "Second Income Quantile") label(3 "Third Income Quantile")) ytitle("Volunteering Rate") xtitle("Year")
cd "$results"
graph export  volunteering_overtime.png, replace
restore


preserve
collapse (mean) hours_volunteer_person, by(year quantile_income)
twoway line hours_volunteer_person year if quantile_income==1 || line hours_volunteer_person year if quantile_income==2 || line hours_volunteer_person year if quantile_income==3, legend(label(1 "First Income Quantile") label(2 "Second Income Quantile") label(3 "Third Income Quantile")) ytitle("Hours Volunteered") xtitle("Year")
cd "$results"
graph export  hs_volunteered_overtime.png, replace
restore

sum hours_volunteer_person if year>2015 & quantile_income==1
sum hours_volunteer_person if year>2015 & quantile_income==2
sum hours_volunteer_person if year>2015 & quantile_income==3
